package com.sgcc.epri.dcloud;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


// @MapperScan 和dao层@Mapper 二选一
@ComponentScan({"com.sgcc.epri.dcloud.*","org.apache.poi.*"})
@EnableAsync
@MapperScan("com.sgcc.epri.dcloud.mapper.dm,com.sgcc.epri.dcloud.mapper.mpp")
@EnableSwagger2
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class SpecialTreatmentApplication {

    // 所有人为操作需记录

    /**
     * 解决Jackson导致Long型数据精度丢失问题
     * @return
     */
    @Bean
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        SimpleModule module = new SimpleModule();
        module.addSerializer(Long.class, ToStringSerializer.instance);
        module.addSerializer(Long.TYPE, ToStringSerializer.instance);
        objectMapper.registerModule(module);
        return objectMapper;
    }

//    /**
//     * 初始化hbase
//     */
//    @Value("${hbase-file}")
//    private String hbaseFile;
//    @Bean
//    public CommandLineRunner run() {
//        return args -> {
//            HBaseUtils2.confDirPath = hbaseFile;
//            HBaseUtils2.loadPro();
//        };
//    }

    public static void main(String[] args) {
        SpringApplication.run(SpecialTreatmentApplication.class, args);
    }



}
